package com.cdp.zwy.zwy_manager_back_v1.controller;

import com.cdp.zwy.zwy_manager_back_v1.common.Result;
import com.cdp.zwy.zwy_manager_back_v1.entity.Employee;
import com.cdp.zwy.zwy_manager_back_v1.service.EmployeeService;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/4/5 12:43
 */
@CrossOrigin
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;
    @PostMapping("/add")
    public Result add(@RequestBody Employee employee){
        return Result.success(employeeService.add(employee));
    }
    @GetMapping("/findAll")
    public Result findAll(){
        return Result.success(employeeService.findAll());
    }
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(employeeService.findById(id));
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        return Result.success(employeeService.deleteById(id));
    }
    @PutMapping("/modify")
    public Result modify(@RequestBody Employee employee){
        return Result.success(employeeService.modify(employee));
    }
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize){
        return Result.success(employeeService.selectPage(pageNum,pageSize));
    }
    @PostMapping("/findByName")
    public Result findByName(@RequestBody Employee employee, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize){
        return Result.success(employeeService.findByName(pageNum, pageSize,employee.getName()));
    }
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(employeeService.deleteBatch(ids));
    }



}

